-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross injection layers in tree-sitter motions #5176
Cross injection layers in tree-sitter motions #5176
Conversation
I think this could be better if we introduce something that wraps the layers in
|
Sounds like such an iterator might go in the same direction as what you did in the rainbow brackets PR? |
They would be similar but the iterator for #2857 covers queries and this would cover walking around the tree without queries. With both together, tree-sitter features are very close to working seemlessly with injections 😀 |
That makes sense. I guess I was thinking that the query iterator could be a special case of the general tree iterator. It all seems pretty related to me. But it probably makes sense to keep the PRs separate. I am mostly just thinking out loud here so my ideas might not be possible as I dont't have time to look at code too closely right now :D |
I just realized this is also an issue in Rust macros since we use injections for those. |
@the-mikedavis what's the status on this PR? i'm interested in this feature and willing to pick it up if necessary/feasible |
I'm still working on this, I have some changes locally. The current approach works ok but it can have some odd edge cases on the injection boundaries. In order to make it work robustly we need to make a tree out of the injection layers and introduce a cursor type that works on that tree similar to |
Hey just wanted to check-in on this PR's status. Love the editor, just getting harder to keep using on my projects based on Svelte. |
4f95972
to
c0bb3af
Compare
I got stuck for a while trying to use the tree cursor with |
c17141d
to
8b5e751
Compare
lets be ambitious and shhot for the next release with this one, I think this mostly looks good, I just found one perf issue and some smaller stuff |
This commit adds a `parent` field to the `LanguageLayer`. This information is conveniently already available when we parse injections. This will be used in the child commit to create a type that can traverse injection layers using this information.
8b5e751
to
7257462
Compare
This uses the layer parentage information from the parent commit to traverse the layers. It's a similar API to `tree_sitter:TreeCursor` but internally it does not use a `tree_sitter::TreeCursor` currently because that interface is behaving very unexpectedly. Using the `next_sibling`/`prev_sibling`/`parent` API on `tree_sitter::Node` reflects the previous code's behavior so this should result in no surprising changes.
This uses the new TreeCursor type from the parent commit to reimplement the tree-sitter motions (`A-p/o/i/n`). Other tree-sitter related features like textobjects are not touched with this change and will need a different, unrelated approach to solve.
7257462
to
6f47990
Compare
Out of curiosity: does this also work for indent queries? Using the above example, if we have an html document and write js in a |
No this doesn't interact with queries. #9320 has some of the foundations for running queries across injection layers but it's limited to textobjects to keep the PR small. Moving indentation queries to use that functionality would be a follow-up change |
Tree-sitter motions didn't work well for languages with injections such as Vue or JavaScript inside HTML since only the root layer's syntax-tree was considered. This change uses the range information for each injected language layer to find the appropriate syntax tree so that tree-sitter motions (A-p, A-i, A-o, A-n) work within injected content.
Here the tree-sitter motions work on the JavaScript syntax tree even though the root layer is HTML. Previously, A-o within the script tag would expand the selection to the whole script tag element.
Closes #2311